#!/usr/bin/env node
const https = require('https'),
      log = console.log,
      cheerio = require('cheerio'),
      addr = 'https://maoyan.com/films?showType=3',
      fs = require('fs');
function getPage(){
  let html = fs.readFileSync('./index.html').toString('utf8');
  return html;
  
}
https.get(addr,(res)=>{

  let infm = [];
  let data = '';
  res.on('data',(chunk)=>data+=chunk);
  res.on('end',()=>{
    let $ = cheerio.load(data);
    //log($)
    let courses1 = $('body').find('div.channel-detail-orange');
    //let courses3 = $('body').find('div.channel-detail-orange>i.fraction');
    
    let courses2 = $('body').find('div.movie-item-title>a');
    
    for(let i=0;i<courses2.length;i++){
      let obj = {};
      let movieid = $(courses2[i]).attr('data-val');
      let id = movieid.slice(9,movieid.length);
      id = id.replace('}','');
      obj.movieID = id;
      obj.moviedName = $(courses2[i]).text();
      obj.movieRange = $(courses1[i]).text();
      infm.push(obj);
    }
    log(infm);
    
    

    
  });
  
});

